﻿using System;
using System.Collections.Generic;
using System.Configuration;
using System.Linq;
using System.Web;
using Messaging.Services;
using Microsoft.Practices.Unity;
using ProgrammingSchool.Core.Interfaces;
using ProgrammingSchool.Core.Services;
using ProgrammingSchool.Repository.Interfaces;
using ProgrammingSchool.Repository.Repositories;

namespace ProgrammingSchool.Core.Factories
{
    public class DefaultContainerFactory
    {
        public IUnityContainer CreateContainer()
        {
            IUnityContainer container = new UnityContainer();
            RegisterApplicationTypes(container);
            return container;
        }

        private void RegisterApplicationTypes(IUnityContainer container)
        {
            RegisterApplicationRepositories(container);
            RegisterApplicationServices(container);
            RegisterMessagingServices(container);
        }

        #region Helpers
        private void RegisterApplicationServices(IUnityContainer container)
        {
            container.RegisterType<IUserService, UserService>();
        }

        private void RegisterApplicationRepositories(IUnityContainer container)
        {
            container.RegisterType<IUsersRepository, UsersRepository>();
        }

        private void RegisterMessagingServices(IUnityContainer container)
        {
            container.RegisterType<IEmailService, EmailService>();
        }

        #endregion
    }
}